<?php

namespace App\Http\Controllers\Api\V1;

use App\Enums\ResponseCode;
use App\Http\Controllers\Api\AbstractApiController;
use App\Services\Search\SearchService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class SearchController extends AbstractApiController
{
    private SearchService $searchService;

    public function __construct(SearchService $searchService)
    {
        $this->searchService = $searchService;
    }

    public function index(): JsonResponse
    {
        if (auth('api')->check()){
            $searchRecords = $this->searchService->getSearchRecords(auth('api')->id());
        }else{
            $searchRecords = collect();
        }
        return self::success(trans("success"),ResponseCode::OK,$searchRecords);
    }
    public function delete(Request $request): JsonResponse
    {
        $id = $request->input('id',0);
        $searchRecords = $this->searchService->delete(auth('api')->user(),$id);
        return self::success(trans("success"),ResponseCode::OK,$searchRecords);
    }
}
